import { FormSchema, BasicColumn } from "/@/components/Table"
import { render } from "/@/utils/common/renderUtils"
import { ResponseMessageType } from "./model"

export enum MpAutoReplyTypeEnum {
  // 关注时回复
  SUBSCRIBE = "1",
  // 收到消息回复
  MESSAGE = "2",
  // 关键词回复
  KEYWORD = "3",
}

// 订阅时回复的消息
export const subscribeReplyColumn: BasicColumn[] = [
  {
    title: "创建时间",
    dataIndex: "responseType",
    ifShow: false,
  },
  {
    title: "回复类型",
    dataIndex: "responseMessageType",
    customRender: ({ text }) => {
      return render.renderTag(render.renderDict(text, "mp_message_type"), "green")
    },
    width: 100,
  },
  {
    title: "回复内容",
    dataIndex: "responseContent",
    customRender: ({ text, record }) => {
      // @ts-ignore
      if (ResponseMessageType.TEXT === record?.responseMessageType) {
        // @ts-ignore
        return record?.responseContent
      }
      // @ts-ignore
      if (ResponseMessageType.IMAGE === record?.responseMessageType) {
        // @ts-ignore
        return render.renderImagePreview({
          // @ts-ignore
          imageList: [{ src: record.responseMediaUrl, width: 80 }],
        })
      }
      // @ts-ignore
      return record?.responseContent
    },
    width: 100,
  },
  {
    title: "创建时间",
    dataIndex: "createdAt",
    width: 100,
  },
]

export const subscribeReplyFormSchema: FormSchema[] = [
  {
    field: "id",
    label: "id",
    show: false,
    component: "Input",
  },
  {
    field: "content",
    label: "回复消息",
    component: "Input",
    slot: "reply",
  },
]
